get-data.RmdSuppose you wish to tabulate ACS one-year 2019 data for estimates of total people by race and ethnicity, as provided in table B03002 by PSRC counties. You would use the following function call:
get_acs_recs(geography = 'county',
table.names = 'B03002',
years = 2019,
acs.type = 'acs1')## # A tibble: 105 x 11
## GEOID name state variable estimate moe label concept census_geography
## <chr> <chr> <chr> <chr> <dbl> <dbl> <chr> <chr> <chr>
## 1 53033 King County Washington B03002_001 2252782 NA Esti~ HISPAN~ County
## 2 53033 King County Washington B03002_002 2030140 NA Esti~ HISPAN~ County
## 3 53033 King County Washington B03002_003 1302544 3208 Esti~ HISPAN~ County
## 4 53033 King County Washington B03002_004 147822 4678 Esti~ HISPAN~ County
## 5 53033 King County Washington B03002_005 13321 1990 Esti~ HISPAN~ County
## 6 53033 King County Washington B03002_006 424590 7085 Esti~ HISPAN~ County
## 7 53033 King County Washington B03002_007 15702 1831 Esti~ HISPAN~ County
## 8 53033 King County Washington B03002_008 6574 3281 Esti~ HISPAN~ County
## 9 53033 King County Washington B03002_009 119587 8804 Esti~ HISPAN~ County
## 10 53033 King County Washington B03002_010 2639 1744 Esti~ HISPAN~ County
## # ... with 95 more rows, and 2 more variables: acs_type <chr>, year <dbl>
By default, without specifying any counties, the jurisdictions returned will be King, Kitsap, Pierce, and Snohomish Counties. Use ?get_acs_recs() for other default values implemented in this function.
To retrieve non-PSRC counties or a subset of the default counties, use the counties argument and provide a vector of counties (e.g. counties = c("King", "Thurston")). Do not use the fips argument as that is reserved for MSA or place geographies.
The get_decennial_recs() to generate Decennial Census tables operates similarly to the get_acs_recs(). If you wanted to retrieve housing units and total population by MSA, you would call the following:
get_decennial_recs(geography = 'msa',
table_codes = c("H001", "P001"),
year = 2010,
fips = c('42660', "28420"))## # A tibble: 4 x 6
## GEOID NAME variable value label concept
## <chr> <chr> <chr> <dbl> <chr> <chr>
## 1 28420 Kennewick-Pasco-Richland, WA Metro Area H001001 93041 Total HOUSING ~
## 2 42660 Seattle-Tacoma-Bellevue, WA Metro Area H001001 1463295 Total HOUSING ~
## 3 28420 Kennewick-Pasco-Richland, WA Metro Area P001001 253340 Total TOTAL PO~
## 4 42660 Seattle-Tacoma-Bellevue, WA Metro Area P001001 3439809 Total TOTAL PO~
Note: the table names are padded with 0s, so you call “H001” as opposed to “H1” as you would in Elmer. Only SF1 tables are currently implemented.
Let’s say you want to create a map of the tracts in the region for one variable. You can use the function create_tract_map(). Here’s an example, mapping non-Hispanic Black or African American population alone by tract:
## Warning: package 'sf' was built under R version 4.0.5
## Warning: package 'dplyr' was built under R version 4.0.5
tract.big.tbl <- get_acs_recs(geography ='tract',
table.names = 'B03002',
years = 2019)
tract.tbl <- tract.big.tbl %>%
filter(label=='Estimate!!Total:!!Not Hispanic or Latino:!!Black or African American alone')
gdb.nm <- "MSSQL:server=AWS-PROD-SQL\\Sockeye; database=ElmerGeo; trusted_connection=yes"
spn <- 2285
tract_layer_name <- "dbo.tract2010_nowater"
tract.lyr <- st_read(gdb.nm, tract_layer_name, crs = spn, quiet = TRUE)
create_tract_map(tract.tbl,
tract.lyr,
map.title='Black, non-Hispanic Population',
map.title.position='topleft',
legend.title='Black, Non-Hispanic Population',
legend.subtitle='by Census Tract')